﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class SmartTriggerConditionsController : ControllerBase
    {

        private readonly ISmartTriggerConditionAppService _app;
        public SmartTriggerConditionsController(ISmartTriggerConditionAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("smartTriggerConditions/{id:Guid}")]
        public ActionResult<SmartTriggerConditionDto> Get([FromRoute] Guid id)
        {
            SmartTriggerConditionDto smartTriggerCondition = _app.Get(id);
            return Ok(smartTriggerCondition);
        }

        [HttpGet]
        [Route("smartTriggers/{smartTriggerId:Guid}/smartTriggerConditions")]
        public ActionResult<IEnumerable<SmartTriggerConditionDto>> GetList([FromRoute] Guid smartTriggerId)
        {
            IEnumerable<SmartTriggerConditionDto> list = _app.GetList(smartTriggerId);
            return Ok(list);
        }

        [HttpPut]
        [Route("smartTriggerConditions/{id:Guid}")]
        public ActionResult<SmartTriggerConditionDto> Put([FromRoute] Guid id, [FromBody] SmartTriggerConditionUpdateDto dto)
        {
            SmartTriggerConditionDto smartTriggerCondition = _app.Update(id, dto);
            return Ok(smartTriggerCondition);
        }

        [HttpPost]
        [Route("smartTriggers/{smartTriggerId:Guid}/smartTriggerConditions")]
        public ActionResult<SmartTriggerConditionDto> Post([FromRoute] Guid smartTriggerId, [FromBody] SmartTriggerConditionCreateDto dto)
        {
            SmartTriggerConditionDto smartTriggerCondition = _app.Add(smartTriggerId, dto);
            return CreatedAtAction(nameof(Get), new { id = smartTriggerCondition.Id }, smartTriggerCondition);
        }

        [HttpDelete]
        [Route("smartTriggerConditions/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
